#include "fu_queue.h"
#include "string.h"




/**
  * @brief  环形队列是否满
  * @param  queue  队列指针
  * @retval 0未满 1 满
  */
uint8_t queue_is_full(st_queue  *queue)
{
    return (queue->front == ((queue->rear+1)%(queue->item_num))) ? 1 : 0;
}

/**
  * @brief  环形队列是否空
  * @param  queue  队列指针
  * @retval 0非空 1 空
  */
uint8_t queue_is_empty(st_queue  *queue)
{
    return (queue->front == queue->rear) ? 1 : 0;
}

/**
  * @brief  环形队列初始化
  * @param  queue  队列指针
  * @retval none
  */
void queue_init(st_queue  *queue,uint8_t item_num,uint8_t item_len,uint8_t *len_buf,uint8_t *data_buf)
{
	queue->front = 0;
	queue->rear = 0;
	queue->item_num = item_num;
	queue->item_len = item_len;
	queue->length = len_buf;
	queue->ring_buff = data_buf;
}

/**
  * @brief  环形队列入队
  * @param  queue  队列指针 data 数据地址 length 长度
  * @retval none
  */
void queue_push(st_queue  *queue,uint8_t * data,uint8_t length)
{
	memcpy(&queue->ring_buff[(queue->rear)*(queue->item_len)],data,length);
	queue->length[queue->rear]=length;
	(queue->rear)++;
	if((queue->rear) >= queue->item_num)
	{
		queue->rear = 0;
	}
}

/**
  * @brief  环形队列出队
  * @param  queue  队列指针 data 数据地址 length 长度
  * @retval none
  */
void queue_pop(st_queue  *queue,uint8_t * data,uint8_t *length)
{
	memcpy(data,&queue->ring_buff[(queue->front)*(queue->item_len)],queue->length[queue->front]);
    * length = queue->length[queue->front];
    (queue->front)++;
	if((queue->front) >= queue->item_num)
	{
		queue->front = 0;
	}
}




